$().ready(function () {
    validateRule();
    $('#apiKey').val(md5(Math.random().toString(36) + Date.now()));
    //时间框
    $(".form_datetime").datetimepicker({
        language : 'zh-CN',
        format: 'yyyy-mm-dd HH:mm:ss',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    $(".form_datetime").val(formatDate(new Date()));
});

$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/pay/payQrConfig/save",
        data: $('#signupForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {

            outChannel: {
                required: true
            },
            accountNo: {
                required: true
            },
            accountName: {
                required: true
            },
            minMoney: {
                required: true
            },
            maxMoney: {
                required: true
            },
            qrs: {
                required: true
            }
        },
        messages: {

            outChannel: {
                required: icon + "请选择支付渠道"
            },
            accountNo: {
                required: icon + "请输入买家账号"
            },
            accountName: {
                required: icon + "请输入卖家旺旺昵称"
            },
            money: {
                required: icon + "请输入金额"
            },
            endDate: {
                required: icon + "请输入失效时间"
            },
            qrs: {
                required: icon + "请输入收款码字符串"
            }
        }
    })
}